﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 通讯录
{
    public class PeoInfo
    {
        string name;
        int age;
        string sex;
        string tele;
        string addr;
        DateTime birth;

        public PeoInfo(string name, string sex, string tele, string addr, DateTime birth)
        {
            this.name = name;
            this.age = GetAgeByBirthdate(birth);
            this.sex = sex;
            this.tele = tele;
            this.addr = addr;
            this.birth = birth;
        }

        private int GetAgeByBirthdate(DateTime birth)
        {
            DateTime now = DateTime.Now;
            int age = now.Year - birth.Year;
            if (now.Month < birth.Month || (now.Month == birth.Month && now.Day < birth.Day))
            {
                age--;
            }
            return age;
        }

        public string getInfo()
        {
            string str = name + "\t" + sex + "\t" + tele + "\t" + addr + "\t" + age.ToString() + "岁" + "\t" + birth.ToString().Substring(0, birth.ToString().IndexOf(" "));
            return str;
        }

        public string getName
        {
            get
            {
                return name;
            }
        }

        public string getSex
        {
            get
            {
                return sex;
            }
        }

        public int getAge
        {
            get
            {
                return age;
            }
        }

        public string getTele
        {
            get
            {
                return tele;
            }
        }

        public string getAddr
        {
            get
            {
                return addr;
            }
        }

        public string getBirth
        {
            get
            {
                return birth.ToString().Substring(0, birth.ToString().IndexOf(" "));
            }
        }

        public DateTime getBirthDate
        {
            get
            {
                return birth;
            }
        }
    }
}
